package com.gagakuai.bpm.api.camunda;


import com.gagakuai.bpm.domian.dto.camunda.WorkflowDefinitionDto;
import com.gagakuai.bpm.domian.dto.request.PageRequest;
import com.gagakuai.bpm.domian.dto.response.PageData;
import com.gagakuai.bpm.domian.dto.response.ResponseStatusDto;
import com.gagakuai.bpm.domian.entity.camuda.WorkflowDefinitionEntity;
import com.gagakuai.bpm.domian.query.camunda.WorkflowQuery;
import com.gagakuai.bpm.service.camunda.WorkflowDefinitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/bpm/definition")
@Api(tags = {"流程定义接口"})
public class WorkflowDefinitionController {

    @Resource
    private WorkflowDefinitionService workflowDefinitionService;

    @ApiOperation("分页获取流程定义列表")
    @PostMapping("/list")
    public ResponseStatusDto<PageData<WorkflowDefinitionDto>> listDefinitionByPage(@RequestBody PageRequest<WorkflowDefinitionDto> pageRequest) {
        return ResponseStatusDto.success(workflowDefinitionService.listDefinitionByPage(pageRequest));
    }

    @ApiOperation("根据用户ID分页获取流程定义列表")
    @PostMapping("/listProcess")
    public ResponseStatusDto<PageData<WorkflowDefinitionEntity>> listProcessByPage(@RequestBody PageRequest<WorkflowQuery> pageRequest) {
        return ResponseStatusDto.success(workflowDefinitionService.listProcessByPage(pageRequest));
    }

    @ApiOperation("流程定义删除")
    @PostMapping("/delete")
    public ResponseStatusDto<Void> deleteProcessDefinition(@RequestBody WorkflowDefinitionDto dto) {
        workflowDefinitionService.deleteProcessDefinition(dto);
        return ResponseStatusDto.success();
    }

    @ApiOperation("流程资源下载")
    @PostMapping("/download")
    public void downloadResourceFile(@RequestBody WorkflowDefinitionDto dto) {
        workflowDefinitionService.downloadResourceFile(dto);
    }

    @ApiOperation("获取定义流程图bpmn 的xml 字符串")
    @GetMapping("/bpmnXml")
    @ApiImplicitParam(value = "流程定义ID", name = "id", required = true)
    public ResponseStatusDto<String> getDefinitionXmlString(String id) {
        return ResponseStatusDto.success(workflowDefinitionService.getDefinitionXmlString(id));
    }

    @ApiOperation("根据实例ID， 获取定义流程图bpmn 的xml 字符串")
    @GetMapping("/getDefinitionXmlByInsId")
    @ApiImplicitParam(value = "流程实例ID", name = "id", required = true)
    public ResponseStatusDto<String> getDefinitionXmlByInsId(String id) {
        return ResponseStatusDto.success(workflowDefinitionService.getDefinitionXmlByInsId(id));
    }
}
